<script setup lang="ts">
import { ref } from "vue";
import { Assignment } from "..";
import { getAllAssignmentByGradeIDAPI } from "../api/assignment";
import AssignmentItem from "../components/assignment/AssignmentItem.vue";
import useUserStore from "../store/userStore";
// import { ElMessage } from "element-plus";

const userStore = useUserStore();

const assignments = ref<Assignment[]>();
const isLoading = ref(true);

getAllAssignmentByGradeIDAPI(userStore.gradeID as number)
  .then((response) => {
    if (response.status !== 200) {
      throw new Error("网络错误");
    }
    return response.data;
  })
  .then((result) => {
    assignments.value = result.data;
    console.log(assignments.value);
    isLoading.value = false;
    // ElMessage({
    //   message: "获得作业成功",
    // });
  });
</script>

<template>
  <el-card class="mx-5 my-6" style="background-color: #84638e; color: white"
    >所有作业</el-card
  >
  <el-col v-loading="isLoading">
    <AssignmentItem
      class="my-4"
      v-for="assignment in assignments"
      :key="assignment.id"
      :assignment="assignment"
    />
  </el-col>
</template>

<style scoped></style>
